<template>
  <el-table
    :data="orders"
    border
    :summary-method="getSummaries"
    show-summary
    style="width: 100%; margin-top: 20px">
    <el-table-column
      prop="course.name"
      label="书名"
      width="546"
      align="center"
    >
    </el-table-column>
    <el-table-column
      prop="time"
      label="书名"
      show-overflow-tooltip
      align="center"
    >
    </el-table-column>
    <el-table-column
      prop="course.price"
      label="商品价格"
      width="546"
      align="center"
    >
    </el-table-column>

  </el-table>


</template>

<script>
import router from "../../router";

export default {
  data() {
    return {
      orders: {},
      allmoney: 0
    }
  },
  created() {
    this.axios.get(this.baseUrl + "order/findallbyid")
      .then(res => {
        console.log(res.data.data);
        //
        this.orders = res.data.data;
        for (let i = 0; i < this.orders.length; i++) {
          this.allmoney += this.orders[i].course.price;
        }

      });
  },

  methods: {
    updateinfo: function () {
      this.axios.post(this.baseUrl + "teacher/updatePhone", this.user)
        .then(res => {

        })
    },
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 元';
          } else {
            sums[index] = '';
          }
        });
        sums[2]=this.allmoney+'元';
        return sums;
      }
    }
}
</script>

<style scoped>
.el-header {
  background-color: #B3C0D1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
